use std::fmt;
pub struct RestoreStatistics {
	file_phase_time:u128,
	chunk_phase_time:u128,
	total_time:u128,
}

impl RestoreStatistics {
	pub fn new() -> Self {
		Self {
			file_phase_time:0,
			chunk_phase_time:0,
			total_time:0,
		}
	}

	pub fn set_file_phase_time(&mut self,value:u128) {
		self.file_phase_time = value;
	}

	pub fn set_chunk_phase_time(&mut self,value:u128) {
		self.chunk_phase_time = value;
	}

	pub fn set_total_time(&mut self,value:u128) {
		self.total_time = value;
	}

	
	pub fn to_simple_table(&self) -> String {
		format!("file\tchunk\ttotal_time\n{}us\t{}us\t{}us",
			self.file_phase_time,
			self.chunk_phase_time,
			self.total_time,
		)
	}

	
	pub fn to_result(&self,is_table:Option<bool>) -> String {
		match is_table {
			Some(true) => self.to_simple_table(),
			_ => format!("{}",self),
		}
	}
}



impl fmt::Display for RestoreStatistics {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		let output = format!(r#"
			file phase cost {}us
			chunk phase cost {}us
			restore totally cost {}us
			"#,
			self.file_phase_time,
			self.chunk_phase_time,
			self.total_time,
		);
		write!(f,"{}",output)
	}
}
